#include "principal.h"
#include "ui_principal.h"

Principal::Principal(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::Principal)
{
  ui->setupUi(this);

  connect(ui->PlayPauseButton, SIGNAL(clicked()), this, SLOT(SwitchGame()));
  connect(ui->ResetButton, SIGNAL(clicked()), this, SLOT(ResetGame()));
  connect(ui->LoadCharacterButton, SIGNAL(clicked()), ui->gLWidget, SLOT(CarregaPersonatge()));
  connect(ui->RotateCharacterSlider, SIGNAL(valueChanged(int)), ui->gLWidget, SLOT(RotateCharacter(int)));
  connect(ui->LoadEnemiesButton, SIGNAL(clicked()), ui->gLWidget, SLOT(CarregaEnemics()));
  connect(ui->EnemyCount, SIGNAL(valueChanged(int)), ui->gLWidget, SLOT(SetEnemyCount(int)));
  connect(ui->CameraResetButton, SIGNAL(clicked()), ui->gLWidget, SLOT(ResetCamera()));
  connect(ui->MapSizeSpin, SIGNAL(valueChanged(int)), ui->gLWidget, SLOT(SetMapSize(int)));
  connect(ui->MapSizeSpin, SIGNAL(valueChanged(int)), ui->MapSizeSlider, SLOT(setValue(int)));
  connect(ui->MapSizeSlider, SIGNAL(valueChanged(int)), ui->MapSizeSpin, SLOT(setValue(int)));
  connect(ui->SwitchCamera, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchCamera()));
  connect(ui->SwitchCulling, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchCulling()));
  connect(ui->SwitchDestruction, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchDestruction()));
  connect(ui->InitialLightCheck, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchInitialLight()));
  connect(ui->InitialLightOptions, SIGNAL(clicked()), ui->gLWidget, SLOT(InitialLightOptionsWidget()));
  connect(ui->SceneLightCheck, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchSceneLight()));
  connect(ui->SceneLightOptionsWidget, SIGNAL(clicked()), ui->gLWidget, SLOT(SceneLightOptionsWidget()));
  connect(ui->SceneLightX, SIGNAL(valueChanged(int)), ui->gLWidget, SLOT(SceneLightPositionX(int)));
  connect(ui->SceneLightZ, SIGNAL(valueChanged(int)), ui->gLWidget, SLOT(SceneLightPositionZ(int)));
  connect(ui->PlayerLightCheck, SIGNAL(clicked()), ui->gLWidget, SLOT(SwitchPlayerLight()));
  connect(ui->PlayerLightOptionsWidget, SIGNAL(clicked()), ui->gLWidget, SLOT(PlayerLightOptionsWidget()));
  paused = true;
}

Principal::~Principal()
{
  delete ui;
}

void Principal::changeEvent(QEvent *e)
{
  QWidget::changeEvent(e);
  switch (e->type()) {
  case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
  default:
    break;
  }
}

void Principal::closeEvent(QCloseEvent *event)
{
  ui->gLWidget->close();
  event->accept();
}

void Principal::SwitchGame() {
  if (ui->gLWidget->SwitchGame()) {
    ui->MapSizeSlider->setEnabled(false);
    ui->MapSizeSpin->setEnabled(false);
    ui->MapSizeLabel->setEnabled(false);
  }
  else {
    ui->MapSizeSlider->setEnabled(true);
    ui->MapSizeSpin->setEnabled(true);
    ui->MapSizeLabel->setEnabled(true);
  }
}

void Principal::ResetGame() {
  ui->gLWidget->ResetGame();
  ui->MapSizeSlider->setEnabled(true);
  ui->MapSizeSpin->setEnabled(true);
  ui->MapSizeLabel->setEnabled(true);
}
